package com.thj.service.impl;

import java.util.List;
import java.util.Map;

import com.commons.po.RolePo;
import com.thj.dao.RoleDao;
import com.thj.dao.impl.RoleDaoImpl;
import com.thj.service.RoleService;

public class RoleServiceImpl implements RoleService {
	
	private RoleDao roleDao=new RoleDaoImpl();
	
	@Override
	public List<RolePo> findByCondition(Map<String, Object> map) {
		List<RolePo> list=roleDao.findByCondition(map);
		for(RolePo r: list){
			System.out.println(r.getRoleId());
		}
		return list;
	}

	@Override
	public RolePo findbyId(Integer id) {
		return roleDao.findbyId(id);
	}

	@Override
	public int updateRolePo(RolePo rolePo) {
		
		return roleDao.updateRolePo(rolePo);
	}

	@Override
	public int saveRole(RolePo rolePo) {
		return roleDao.saveRole(rolePo);
	}

	@Override
	public int saveRoleMenu(Integer roleId, List<Integer> menuIdList) {
		//1、先删除roleId所配置的所有菜单关联
		roleDao.deleteRoleMenu(roleId, null);
		//2、遍历menuIdList再新增到角色与菜单的中间表中
		if(menuIdList!=null && menuIdList.size()>0){
			for(Integer menuId:menuIdList){
				roleDao.saveRoleMenu(roleId, menuId);
			}
		}
		return 1;
	}

}
